package contents.entities;

import java.util.Comparator;
import java.text.ParseException;

public class Tutorage {
    public static class ByDateComparator implements Comparator {
        public int compare(Object object1, Object object2) {
            Tutorage tutorage1 = (Tutorage) object1;
            Tutorage tutorage2 = (Tutorage) object2;
            
            java.text.SimpleDateFormat datetimeFormat = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            try {
                java.util.Date date1 = datetimeFormat.parse(tutorage1.getDateString() + " " + tutorage1.getTimeString());
                java.util.Date date2 = datetimeFormat.parse(tutorage2.getDateString() + " " + tutorage2.getTimeString());
                // return negative of result, newer dates go first
                return -date1.compareTo(date2);
            } catch (ParseException exception) {
                // this should never happen
                return 0;
            }
        }   
    }
    
    private int tutorageId;
    private Subject subject;
    private Student student;
    private String type;
    private String className;
    private String dateString;
    private String timeString;

    public Tutorage(int tutorageId, Subject subject, Student student, String type, String className, String dateString, String timeString) {
        this.tutorageId = tutorageId;
        this.subject = subject;
        this.student = student;
        this.type = type;
        this.className = className;
        this.dateString = dateString;
        this.timeString = timeString;
    }

    public Student getStudent() {
        return student;
    }

    public Subject getSubject() {
        return subject;
    }

    public int getTutorageId() {
        return tutorageId;
    }

    public String getType() {
        return type;
    }

    public String getClassName() {
        return className;
    }

    public String getDateString() {
        return dateString;
    }

    public String getTimeString() {
        return timeString;
    }
}
